﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common.Wechat.Model;
using Common.Wechat.Service;

namespace Common.Wechat.Test
{
    public class TestSendMessage
    {
        public static void SendText()
        {
            //发送文字消息
            CorpTextMessage ctx = new CorpTextMessage
            {
                touser = "hufeifei",//|daizilin
                toparty = "",
                totag = "",
                text = new Text { content = "你的快递已到，请携带工卡前往邮件中心领取。\n出发前可查看<a href=\"http://work.weixin.qq.com\">邮件中心视频实况</a>，聪明避开排队。" },
                safe = 1
            };
            ICropMessage cm = new CropMessage();
            CommonResult result = cm.SendMessage(ctx);
        }

        //发送已存在图文素材的图文消息
        public static void SendNews()
        {
            CorpMpnewsMessage ctx = new CorpMpnewsMessage
            {
                touser = "Q-0194",
                toparty = "",
                totag = "",
                mpnews = new MpNews { media_id = "25HGfQxHkUoJJ7LnVU_YyFR2SAg4JFcysBOzlLUg9JRRLPkUJiEG4T1vh5GAO-fIt" },
                safe = 1
            };

            ICropMessage cm = new CropMessage();
            CommonResult result = cm.SendMessage(ctx);
        }

        public static void SendMsgText()
        {
            CopyDetailMessage cdm = new CopyDetailMessage
            {
                touser = "hufeifei",
                toparty = "",
                totag = "",
                textcard = new CopyDetailMessageCard
                {
                    description = "<div class=\"gray\">2018年7月11日</div><br><div class=\"normal\">您名下有10个未处理的案件，尽快处理</div><div class=\"highlight\">请于2018年7月12日前向领导汇报</div>",
                    title = "消息提醒",
                    url = "http://www.baidu.com/",
                    btntxt = "更多"
                },
                safe = 1
            };
            ICropMessage cm = new CropMessage();
            CommonResult result = cm.SendMessage(cdm);
        }

        //发送不存在图文素材的图文消息
        public static void SendNews2()
        {
            //{
            //    "touser": "UserID1|UserID2|UserID3",
            //    "toparty": " PartyID1 | PartyID2 ",
            //    "totag": " TagID1 | TagID2 ",
            //    "msgtype": "mpnews",
            //    "agentid": 1,
            //    "mpnews": {
            //        "articles":[
            //            {
            //                "title": "Title",
            //                "thumb_media_id": "id",
            //                "author": "Author",
            //                "content_source_url": "URL",
            //                "content": "Content",
            //                "digest": "Digest description",
            //                "show_cover_pic": "0"
            //            },
            //            {
            //                "title": "Title",
            //                "thumb_media_id": "id",
            //                "author": "Author",
            //                "content_source_url": "URL",
            //                "content": "Content",
            //                "digest": "Digest description",
            //                "show_cover_pic": "0"
            //            }
            //        ]
            //    },
            //    "safe":0
            //}
            //1.上传图片
            ICropMaterial icm = new CropMaterial();
            string media_id = "";
            CommonResult result = icm.Add("image", @"D:\投标助手图片\03.png", ref media_id);
            //2.图文素材清单
            List<MpNewsArticle> lst = new List<MpNewsArticle>()
            {
                new MpNewsArticle{title = "发现大自然的魅力",
                    thumb_media_id=media_id,
                    author="Eva",
                    content_source_url="",
                    content="发现大自然的魅力</br>这是一颗美丽的多肉植物",
                    digest="这是一颗美丽的多肉植物",
                    show_cover_pic="1"}
            };
            CorpMpnewsMessage ctx = new CorpMpnewsMessage
            {
                touser = "hufeifei",
                toparty = "",
                totag = "",
                mpnews = new MpNews { articles = lst },
                safe = 1
            };
            ICropMessage cm = new CropMessage();
            result = cm.SendMessage(ctx);
        }
    }
}
